home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Classes / DE_SerialSolutions2.0 / Reader<3.0> / Reader.m < prev    next >
Encoding:
Text File  |  1992-08-12  |  1.2 KB  |  94 lines

  1.  
  2. #import "Reader.h"
  3.  
  4. @implementation Reader
  5.  
  6.  
  7. - init:( char*) portName baudrate:(int) baudRate
  8. {
  9. int ok;
  10.     [super init];
  11.     strcpy(readString,"");
  12.     termChar = '\r';        //most common.
  13.     target = nil;
  14.      ok = [self openRAW:portName Baudrate:baudRate ];
  15.     if( ok == SERIALOK)
  16.     {
  17.         [self setTerm:'\r'];
  18.     }
  19.     else
  20.     {
  21.         NXRunAlertPanel("Reader","%s\nDid Not Open","OK",NULL,NULL,portName);
  22.         [NXApp terminate:nil];
  23.     }
  24.     [self setNotify:@selector(charsReady) with:self];
  25.     [self setCharacterTimeout: 5 * SEC];
  26.     return self;
  27. }
  28.  
  29.  
  30. - (SEL) action
  31. {
  32.     return action;
  33. }
  34.  
  35. - setAction:(SEL) aSelector
  36. {
  37.     action = aSelector;
  38.     return self;
  39. }
  40.  
  41. - setTarget:anObject
  42. {
  43.     target = anObject;
  44.     return self;
  45. }
  46.  
  47. - target
  48. {
  49.     return target;
  50. }
  51.  
  52. - setTarget:(SEL) theTarget andID: theID
  53. {
  54.     action  = theTarget;
  55.     target = theID;
  56.     return self;
  57. }
  58.  
  59. - setTerm:(char) term
  60. {
  61.     termChar = term;
  62.     return self;
  63. }
  64.  
  65. //Now for the internal methods...
  66. - charsReady
  67. {
  68. int numRead;
  69. BOOL ok = YES;
  70.  
  71.     numRead = [self readString: readString forMaxOf:READSTRINGSIZE -1 term:termChar];
  72.     //do any parsing or error checking here
  73.     //set ok = NO...
  74.     if( ok )
  75.     {
  76.         if( target != nil)
  77.             [ target perform:action with:self];
  78.     }
  79.     else
  80.     {
  81.         NXBeep();
  82.     }
  83.     return self;
  84. }
  85.  
  86. - (const char*) stringValue
  87. {
  88.     return readString;
  89. }
  90.  
  91. @end
  92.  
  93.  
  94.